package com.touch.plugin;
import java.awt.*;
import java.net.*;
import javax.swing.*;
import com.touch.core.*;
/*
 * Copyright (c) 2009, TOD Productions All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *	- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *	- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *	-Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */
/**
 * The ServerTray creates a System Tray icon that acts as the main GUI for the server.
 */
public final class PServerTray implements IPlugin
{	
	public void load()
	{
		
	}
	public Object execute1(Object... args)
	{
		if(!SystemTray.isSupported())
		{
			JOptionPane.showConfirmDialog(null, "System Tray is not supported!", "Error", JOptionPane.WARNING_MESSAGE, JOptionPane.OK_OPTION);
			return null;
		}
		
		try
		{
			//loads the icon as an ImageIcon
			icon 		= new ImageIcon(new URL("http://code.google.com/p/eclipse-mmorpgmaker/logo?logo_id=1242512328"));
			//converts the icon to a TrayIcon
			trayIcon 	= new TrayIcon(icon.getImage(), " Server", null);
			//Link to the SystemTray
			tray 		= SystemTray.getSystemTray();
			//menu that the SystemTray calls.
			menu 		= new PServerMenu();
					
			//change the tray icon's size to match the System's
			trayIcon.setImageAutoSize(true);
			//adds the menu be opened wiPluginBaseth the icon.
			trayIcon.setPopupMenu(menu);
			//add the icon to the tray
			tray.add(trayIcon);
			System.out.println("loaded ServerTray");
		}
		catch(final Exception e)
		{
			e.printStackTrace();
		}		
	}	
	//menu that the Server can control
	private PServerMenu menu;
	//icon that the Server uses in the System Tray
	private ImageIcon icon;
	//converted icon 
	private TrayIcon trayIcon;
	//pointer to the system's tray.
	private SystemTray tray;
	public Object execute(Object... args) {
		this.execute1();
		return null;
	}
}
